using System;

namespace Ayatta.Contract.Domain
{
    /// <summary>
    /// 子订单
    /// </summary>
    public class OrderItem : Versionable<string>
    {
        /// <summary>
        /// 父订单号
        /// </summary>
        public string OrderId { get; set; }

        /// <summary>
        /// 商品的最小库存单位Sku的Id
        /// </summary>
        public int SkuId { get; set; }

        /// <summary>
        /// 商品Id
        /// </summary>
        public int ItemId { get; set; }

        /// <summary>
        /// 产品Id
        /// </summary>
        public int ProductId { get; set; }

        /// <summary>
        /// 商品对应的类目Id
        /// </summary>
        public int CategoryId { get; set; }

        /// <summary>
        /// 商品对应的根类目Id
        /// </summary>
        public int CategoryRootId { get; set; }

        /// <summary>
        /// 商家外部编码(可与商家外部系统对接)
        /// </summary>
        public string OuterId { get; set; }

        /// <summary>
        /// 套餐Id
        /// </summary>
        public int MealId { get; set; }

        /// <summary>
        /// 套餐的值 如：M8原装电池:便携支架:M8专用座充:莫凡保护袋
        /// </summary>
        public string MealName { get; set; }

        /// <summary>
        /// 商品标题
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// 商品图片的绝对路径
        /// </summary>
        public string PictureUrl { get; set; }

        /// <summary>
        /// SKU的值 如 颜色:桔色;尺码:M
        /// </summary>
        public string Properties { get; set; }

        /// <summary>
        /// 购买数量 取值范围:大于零的整数
        /// </summary>
        public int Quantity { get; set; }

        /// <summary>
        /// 商品价格 精确到2位小数;单位:元 如:200.07，表示:200元7分
        /// </summary>
        public decimal Price { get; set; }

        /// <summary>
        /// 订单优惠金额 精确到2位小数;单位:元
        /// </summary>
        public decimal Discount { get; set; }

        /// <summary>
        /// 手工调整金额 精确到2位小数;单位:元
        /// </summary>
        public decimal Adjust { get; set; }

        /// <summary>
        /// 应付金额（商品价格 * 商品数量 + 手工调整金额 - 订单优惠金额）。精确到2位小数;单位:元。
        /// </summary>
        public decimal Total { get; set; }

        /// <summary>
        /// 子订单实付金额
        /// </summary>
        public decimal Paid { get; set; }

        /// <summary>
        /// 子订单的运送方式
        /// </summary>
        public ShippingType ShippingType { get; set; }

        /// <summary>
        /// 买家Id
        /// </summary>
        public int BuyerId { get; set; }

        /// <summary>
        /// 卖家Id
        /// </summary>
        public int SellerId { get; set; }

        /// <summary>
        /// 拍品Id
        /// </summary>
        public int? AuctionId { get; set; }

        /// <summary>
        /// 拍品等级
        /// </summary>
        public AuctionGrade? AuctionGrade { get; set; }

        /// <summary>
        /// 是否为赠品
        /// </summary>
        public bool IsGift { get; set; }

        /// <summary>
        /// 是否是服务订单 是返回true，否返回false
        /// </summary>
        public bool IsService { get; set; }

        /// <summary>
        /// 是否为虚拟物品
        /// </summary>
        public bool IsVirtual { get; set; }

        /// <summary>
        /// 子订单的交易结束时间 说明：子订单有单独的结束时间，与主订单的结束时间可能有所不同，在有退款发起的时候或者是主订单分阶段付款的时候，子订单的结束时间会早于主订单的结束时间
        /// </summary>
        public DateTime? EndTime { get; set; }

        /// <summary>
        /// 订单超时到期时间 格式:yyyy-MM-dd HH:mm:ss
        /// </summary>
        public DateTime ExpirationTime { get; set; }

        /// <summary>
        /// 捆绑的子订单号，表示该子订单要和捆绑的子订单一起发货，用于子订单捆绑发货
        /// </summary>
        public string BindId { get; set; }

        /// <summary>
        /// 物流订单Id
        /// </summary>
        public string ShippingId { get; set; }

        /// <summary>
        /// 子订单发货的物流公司名称
        /// </summary>
        public string ShippingCompany { get; set; }

        /// <summary>
        /// 子订单所在包裹的运单号
        /// </summary>
        public string ExpressNo { get; set; }

        /// <summary>
        /// 子订单发货时间，当卖家对订单进行了多次发货，子订单的发货时间和主订单的发货时间可能不一样了，那么就需要以子订单的时间为准。（没有进行多次发货的订单，主订单的发货时间和子订单的发货时间都一样）
        /// </summary>
        public DateTime? ConsignTime { get; set; }

        /// <summary>
        /// 最近退款Id
        /// </summary>
        public string RefundId { get; set; }

        /// <summary>
        /// 退款状态
        /// </summary>
        public RefundStatus? RefundStatus { get; set; }

        /// <summary>
        /// 子订单状态
        /// </summary>
        public OrderStatus Status { get; set; }

        /// <summary>
        /// 扩展信息
        /// </summary>
        public string Extra { get; set; }

        /// <summary>
        /// 最后一次编辑时间
        /// </summary>
        public DateTime ModifiedOn { get; set; }

        public string[] GetProperties()
        {
            return !string.IsNullOrEmpty(Properties) ? Properties.Split(';') : new string[0];
        }

        /// <summary>
        /// 关联订单
        /// </summary>
        public virtual Order Order { get; set; }

        /*
        public decimal SubTotal
        {
            get { return Price*Quantity - Discount; }
        }
        
        #region Navigation Properties      

        ///// <summary>
        ///// 关联礼品卡
        ///// </summary>
        //public virtual IList<GiftCard> AssociatedGiftCards { get; set; }

        #endregion
         */
    }
}